// pages/personal/accountdetails/accountdetails.js
var utils = require('../../../utils/util.js');
console.log(utils);
Page({

    /**
     * 页面的初始数据
     */
    data: {
        currentPage:1,
        dateValue:""
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that=this;
        var dateValue = utils.formatdate(new Date());
        that.setData({
            dateValue: dateValue
        })
        that.tradelogList(that.data.dateValue,that.data.currentPage);
    },
    //获取余额列表
    tradelogList: function (dateValue,currentPage) {
        var that = this;
        utils.showLoading();
        utils.http("/api/v1/member/trade_log", { date:dateValue, page: currentPage}, function (res) {
            utils.hideLoading();
            var allpost = that.data.list;
            if (allpost == undefined) {
                allpost = [];
            }
            for (var i in res.datas) {
                allpost.push(res.datas[i]);
            }
            if (res.datas.length < 10) {
                that.setData({
                    tishi_title: '已加载全部',
                });
            } else {
                that.setData({
                    tishi_title: '加载更多',
                });
            }
            that.setData({
                list: allpost,
                ready: res.datas.length == 0 ? 1 : 2,
            })
        })
    },
    bindDateChange(e) {
        var that=this;
        this.setData({
            dateValue: e.detail.value,
            currentPage:1,
            list:[]
        })
        that.tradelogList(e.detail.value, that.data.currentPage);
    },
    /**
 * 页面上拉触底事件的处理函数
 */
    onReachBottom: function () {
        var that = this;
        if (that.data.ready == 2) {
            var page = that.data.currentPage + 1
            that.setData({
                currentPage: page,
            })
            that.tradelogList(that.data.dateValue, page);
        }

    },
})